<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    body {
        background-color: #eee;
    }

    #app {
        background-color: #fff;
        width: 500px;
        margin: 50px auto;
        box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
        padding: 2em;
    }

    .box {
        padding: 1em;
        border: 1px solid #ccc;
        margin: 1em;
    }
</style>

<body>
    <div id="app">
        <my-com1></my-com1>
        <my-com2></my-com2>
    </div>
    <div id="app2">
        <my-com1></my-com1>
    </div>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.11/vue.js"></script>
    <script>
        //定义组件
        Vue.component('MyCom1', {
            template: `
            <div>
                我是一个组件
                {{num}}
                <button @click="dianji" >按钮+1</button>
                </div>
            `,
            data() {
                return {
                    num: 100
                }
            },
            methods: {
                dianji() {
                    this.num++
                }
            }
        })
        let vm = new Vue({
            el: '#app',
            //定义局部组件
            components: {
                "MyCom2": {
                    template: `
                    <div>
                        这个一个局部组件
                    </div>
                    `
                }
            }
        })
        new Vue({
            el: '#app2',

        })
    </script>
</body>

</html>